import { useEffect, useState, } from 'react'
import { getHCard } from '../api/api'
import { Button } from 'antd-mobile'
import { useHistory, useParams } from 'react-router-dom'
type ParamsType = {
    id: string;
}
export default function HospitalCard() {
    const [list, setList] = useState([])
    const history = useHistory()
    const { id } = useParams<ParamsType>()
    const getCard = async () => {
        const data = await getHCard()
        setList(data.data.rows)
    }
    const toCard = () => {
        history.push('/outpatient/hospitalList/detail/' + id + '/card/add')
    }
    const toCard1 = (idm: any) => {
        history.push('/outpatient/hospitalList/detail/' + id + '/card/add/' + idm)
    }
    useEffect(() => {
        getCard()
        console.log(list);
    }, [])

    if (list.length > 0) {
        return (
            <div>
                {/* <div>
                <li>姓名:张泊文</li>
                <li>生日:1999/11/26</li>
                <li>住址:黄土高坡</li>
                <li>身份证:5151515451512</li>
                <button >编辑</button>
                <hr />
            </div> */}
                {list.map((item: any) => {
                    return <div>
                        <li>姓名:{item.name}</li>
                        <li>生日:{item.birthday}</li>
                        <li>住址:{item.address}</li>
                        <li>sfz:{item.cardId}</li>
                        <Button onClick={() => { toCard1(item.id) }} size='mini' color='primary'>
                            编辑
                        </Button>
                        <hr />
                    </div>
                })}
                <Button onClick={() => { toCard() }} block color='primary' size='large'>添加就诊人</Button>
            </div>
        )
    } else {
        return <div></div>
    }
}
